package cn.iocoder.yudao.module.dine.config.service.admin;

import cn.iocoder.yudao.framework.business.basic.dao.query.CoreLambdaQueryWrapper;
import cn.iocoder.yudao.framework.business.basic.dao.query.CoreQueryWrapper;
import cn.iocoder.yudao.framework.business.basic.pojo.dto.SimpleQueryDTO;
import cn.iocoder.yudao.framework.business.basic.service.CrudService;
import cn.iocoder.yudao.framework.business.basic.service.impl.BaseService;
import cn.iocoder.yudao.module.api.dine.vo.DineTimeRangeVO;
import cn.iocoder.yudao.module.dine.config.convert.DineTimeRangeConvert;
import cn.iocoder.yudao.module.dine.config.dao.DineTimeRangeMapper;
import cn.iocoder.yudao.module.dine.config.pojo.dto.DineTimeRangeSaveDTO;
import cn.iocoder.yudao.module.dine.config.pojo.po.DineTimeRange;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * 服务
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/09/07
 */
@Service
public class DineTimeRangeService extends BaseService<DineTimeRange, DineTimeRangeVO, SimpleQueryDTO> implements CrudService<DineTimeRange, DineTimeRangeVO, DineTimeRangeSaveDTO, SimpleQueryDTO> {
    @Resource
    private DineTimeRangeMapper dineTimeRangeMapper;

    @Override
    public DineTimeRangeMapper getInjectedMapper() {
        return dineTimeRangeMapper;
    }

    @Nonnull
    @Override
    protected CoreQueryWrapper<DineTimeRange> buildQueryWrapper(SimpleQueryDTO param) {
        return super.buildQueryWrapper(param);
    }

    @Override
    public DineTimeRangeVO convertToViewObject(DineTimeRange entity) {
        return DineTimeRangeConvert.INSTANCE.toViewObject(entity);
    }

    @Override
    public DineTimeRange convertToEntity(DineTimeRangeSaveDTO param) {
        return DineTimeRangeConvert.INSTANCE.toEntity(param);
    }

    @Override
    public <P> boolean checkExists(P param) {
        CoreLambdaQueryWrapper<DineTimeRange> wrapper = new CoreLambdaQueryWrapper<>();
        wrapper.eq(DineTimeRange::getCategoryId, ((DineTimeRangeSaveDTO) param).getCategoryId());
        Long l = dineTimeRangeMapper.selectCount(wrapper);
        return l != null && l > 0;
    }

}
